package singleton

import (
	"sync"
	"sync/atomic"
)

type RoleApiSingleton struct {
	RoleApiMap  *sync.Map
	RoleInfoMap *sync.Map
}

var (
	instance atomic.Value
	mu       sync.Mutex
)

// init 初始化
func init() {
	instance.Store(&RoleApiSingleton{})
}

// GetInstance 获取单例
func GetInstance() *RoleApiSingleton {
	return instance.Load().(*RoleApiSingleton)
}

// Refresh 刷新单例（加锁更新）
func Refresh(newData string) {
	mu.Lock()
	defer mu.Unlock()
	instance.Store(&RoleApiSingleton{})
}
